package org.example.Controller;

import com.alibaba.druid.util.StringUtils;
import jakarta.annotation.Resource;
import org.example.common.Result;
import org.example.common.ResultCodeEnum;
import org.example.mapper.AdminMapper;
import org.example.pojo.Admin;
import org.example.pojo.Business;
import org.example.pojo.Query;
import org.example.service.AdminService;
import org.example.service.BusinessService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/admin")
public class AdminController {
    @Resource
    private BusinessService businessService;
    @Resource
    private AdminService adminService;

    @PostMapping("/login")
    public Result login(@RequestBody Admin admin){
        if(admin.getRole().equals("ADMIN")){
            Result result=adminService.login(admin);
            return result;
        }else{
            Result result=businessService.login(admin);
            return result;
        }
    }
    @PostMapping("/register")
    public Result Register(@RequestBody Business business){
      Result result=  businessService.register(business);
        return result;
    }
    @PostMapping("/registeradmin")
    public Result Registeradmin(@RequestBody Admin admin){
        Result result=adminService.register(admin);
        return result;
    }
    @PostMapping("/list")
    public Result list(@RequestBody Query query){
        Result result=adminService.getlist(query);
        return result;
    }
    @PostMapping("/add")
    public Result add(@RequestBody Admin admin){
        Result result=adminService.add(admin);
        return result;

    }
    @PostMapping("/update")
    public Result update(@RequestBody Admin admin){
        Result result=adminService.updateadmin(admin);
        return result;

    }
    @PostMapping("/delete")
    public Result shanchu(Integer id){
        Result result=adminService.deleteadmin(id);
        return result;

    }



}
